# -* - coding: UTF-8 -* - 
#import sys
#reload(sys)
#sys.setdefaultencoding('utf8')

import threading,string,os
from base_thread import Thread
from time import sleep
from task import *
from notify.thread import *
import logging

#从外部队列读取消息放入内部对列
class NotifyFactory():  
	def __init__(self,serverFactory,clientFactory,notifyCenter,config):
		self.serverFactory=serverFactory
		self.clientFactory=clientFactory
		self.center = notifyCenter
		self.config=config
		self.threads=[]
		self.clientDriver = 'http'
		self.create()	
		
		
		
	#生成队列
	def create(self):
		#queue队列
		notify_count = self.config.get_int('coop','notify_count',1)
		for i in range(notify_count):#10线程执行
			client=self.clientFactory.create(self.config,self.clientDriver)
			t = NotifyThread(client,self.center)  
			self.threads.append(t)

	#启动
	def start(self):
		for t in self.threads:
			t.start_thread()
	
	#停止
	def stop(self):
		logging.info("NOTIFY Thread Stop!")			
		for t in self.threads:
			t.stop_thread()	
	#停止
	def terminate(self):
		logging.info("NOTIFY Thread Terminate!")			
		for t in self.threads:
			t.terminate()	